/**   
 * @Title: ShowZhanji.java 
 * @Package: com.esun.util.img 
 * @Description: 战绩计算 
 * @Author: Kael gaojian@500wan.com   
 * @Date: 2012-3-15 上午10:30:38  
 * Copyright (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.util;

import java.util.ArrayList;

import android.content.Context;
import android.widget.ImageView;

import com.esun.cheetah.config.Config;

/**
 * 
 * @Package com.esun.util.ShowZhanji
 * @ClassName: ShowZhanji
 * @Description: TODO(战绩计算)
 * @author 孔祥攀 <br/>
 * @date 2012-4-23 下午5:00:05
 * 
 */
public class ShowZhanji {
	private ImageZhanJi image = ImageZhanJi.getInstace();

	private Context context;

	public ShowZhanji(Context con) {
		context = con;
	}

	public ArrayList<ImageView> showzhanji(String golddiamond,
			String silverdiamond, String goldstar, String silverstar) {
		// 存放图片id的list
		ArrayList<ImageView> list = new ArrayList<ImageView>();
		// 金钻数
		int golddiamondnum = 0;
		// 银钻数
		int silverdiamondnum = 0;
		// 金星数
		int goldstarnum = 0;
		// 银星数
		int silverstarnum = 0;
		// 金杯数
		int goldcupnum = 0;
		// 传入的字符串不为空，不为“”
		if ((golddiamond != null) && (!golddiamond.equals(Config.NULLMARK))) {
			golddiamondnum = Integer.parseInt(golddiamond);
		}
		if ((silverdiamond != null) && (!silverdiamond.equals(Config.NULLMARK))) {
			silverdiamondnum = Integer.parseInt(silverdiamond);
		}
		if ((goldstar != null) && (!goldstar.equals(Config.NULLMARK))) {
			goldstarnum = Integer.parseInt(goldstar);
		}
		if ((silverstar != null) && (!silverstar.equals(Config.NULLMARK))) {
			silverstarnum = Integer.parseInt(silverstar);
		}
		// if ((goldcup != null) && (!goldcup.equals(Config.NULLMARK))) {
		// goldcupnum = Integer.parseInt(goldcup);
		// }
		// 将金钻ImageView放入list
		if (golddiamondnum != 0) {
			ImageView imagegolddiamond = new ImageView(context);
			if (golddiamondnum <= 9) {
				imagegolddiamond.setBackgroundResource(image
						.getGoldenDiamond(golddiamondnum - 1));
			} else {// 大于9的都显示9+
				imagegolddiamond.setBackgroundResource(image
						.getGoldenDiamond(9));
			}
			list.add(imagegolddiamond);
		}

		// 将银钻ImageView放入list
		if (silverdiamondnum != 0) {
			ImageView imagesilverdiamond = new ImageView(context);
			imagesilverdiamond.setBackgroundResource(image
					.getSilverDiamond(silverdiamondnum - 1));
			list.add(imagesilverdiamond);
		}

		// 将金星图片id放入list
		if (goldstarnum != 0) {
			ImageView imagegoldstar = new ImageView(context);
			if (goldstarnum <= 9) {
				imagegoldstar.setBackgroundResource(image
						.getGolenStart(goldstarnum - 1));
			} else {// 大于9的都显示9+
				imagegoldstar.setBackgroundResource(image.getGolenStart(9));
			}
			list.add(imagegoldstar);
		}

		// 将银星图片id放入list
		if (silverstarnum != 0) {
			ImageView imagesilverstar = new ImageView(context);
			imagesilverstar.setBackgroundResource(image
					.getSilverStart(silverstarnum - 1));
			list.add(imagesilverstar);
		}

		// 将金杯图片id放入list
		if (goldcupnum != 0) {
			// 不带9的金杯
			int goldcupNum = goldcupnum % 9;
			// 带9的金杯
			int goldcupNumNine = goldcupnum / 9;
			ImageView imagegoldcupnine = new ImageView(context);
			ImageView imagegoldcup = new ImageView(context);
			if (goldcupNumNine != 0) {
				if (goldcupNumNine <= 9) {
					imagegoldcupnine.setBackgroundResource(image
							.getGoldCup(goldcupNumNine - 1));

				} else {
					imagegoldcupnine.setBackgroundResource(image.getGoldCup(9));
				}
				list.add(imagegoldcupnine);
			}
			if (goldcupNum != 0) {
				imagegoldcup.setBackgroundResource(image
						.getGoldCup(goldcupNum - 1));
				list.add(imagegoldcup);
			}
		}
		return list;
	}
}
